<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>zapmenot.source &mdash; Zapmenot 0.1 documentation</title>
      <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
      <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/sphinx_highlight.js"></script>
    <script src="../../_static/js/theme.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" /> 
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
            <a href="../../index.html" class="icon icon-home"> Zapmenot
          </a>
              <div class="version">
                0.1
              </div>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <ul>
<li class="toctree-l1"><a class="reference internal" href="../../license.html">Licence &amp; Disclaimer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../getting-started.html">Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../materials.html">Material Library</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../isotopes.html">Isotope Library</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modeling.html">Modeling in ZapMeNot</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../results.html">Generating Results</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../graphics.html">We Want Pictures!</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../theory-and-methods.html">Theory and Methods</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../benchmarks.html">Benchmarking</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../module-docs.html">Module Contents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../developer.html">Developer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../version-history.html">Version History</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">Zapmenot</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../index.html" class="icon icon-home"></a></li>
          <li class="breadcrumb-item"><a href="../index.html">Module code</a></li>
      <li class="breadcrumb-item active">zapmenot.source</li>
      <li class="wy-breadcrumbs-aside">
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <h1>Source code for zapmenot.source</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">abc</span>
<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">enum</span> <span class="kn">import</span> <span class="n">Enum</span>

<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">shield</span><span class="p">,</span> <span class="n">isotope</span>

<span class="kn">import</span> <span class="nn">importlib</span>
<span class="n">pyvista_spec</span> <span class="o">=</span> <span class="n">importlib</span><span class="o">.</span><span class="n">util</span><span class="o">.</span><span class="n">find_spec</span><span class="p">(</span><span class="s2">&quot;pyvista&quot;</span><span class="p">)</span>
<span class="n">pyvista_found</span> <span class="o">=</span> <span class="n">pyvista_spec</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
<span class="k">if</span> <span class="n">pyvista_found</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">pyvista</span>

<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="GroupOption"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.GroupOption">[docs]</a><span class="k">class</span> <span class="nc">GroupOption</span><span class="p">(</span><span class="n">Enum</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;Set of possible energy group options.  The options</span>
<span class="sd">    include &#39;group&#39;, &#39;discrete&#39;, and &#39;hybrid&#39;.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">GROUP</span> <span class="o">=</span> <span class="s2">&quot;group&quot;</span>
    <span class="n">HYBRID</span> <span class="o">=</span> <span class="s2">&quot;hybrid&quot;</span>
    <span class="n">DISCRETE</span> <span class="o">=</span> <span class="s2">&quot;discrete&quot;</span></div>

<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="Source"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.Source">[docs]</a><span class="k">class</span> <span class="nc">Source</span><span class="p">(</span><span class="n">abc</span><span class="o">.</span><span class="n">ABC</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;Abtract class to model a radiation source.</span>

<span class="sd">    Maintains a list of isotopes and can return a list of point source</span>
<span class="sd">    locations within the body of the Source.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    **kwargs</span>
<span class="sd">        Arbitrary keyword arguments.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<span class="w">    </span><span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    _points_per_dimension : :class:`list` of integers</span>
<span class="sd">        The number of source points to be used in each dimension when modeling</span>
<span class="sd">        the uniform source distribution throughout the body of the source.</span>
<span class="sd">        Typically a list of three integers for three-dimensional sources, one</span>
<span class="sd">        integer for one dimensional sources, and not significant for point</span>
<span class="sd">        sources.</span>
<span class="sd">    &#39;&#39;&#39;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&#39;&#39;&#39;Initialize the Source with empty strings for the isotope list</span>
<span class="sd">        and photon list&#39;&#39;&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_isotope_list</span> <span class="o">=</span> <span class="p">[]</span>   <span class="c1"># LIST of isotopes and activities (Bq)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_unique_photons</span> <span class="o">=</span> <span class="p">[]</span>  <span class="c1"># LIST of unique photons and activities (Bq)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span> <span class="o">=</span> <span class="p">[</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_include_key_progeny</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_max_photon_energies</span> <span class="o">=</span> <span class="mi">30</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_grouping_option</span> <span class="o">=</span> <span class="n">GroupOption</span><span class="o">.</span><span class="n">HYBRID</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">grouping</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;:class:`GroupOption` : State defining the photon energy group</span>
<span class="sd">        option.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_grouping_option</span>

    <span class="nd">@grouping</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">grouping</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;:class:`GroupOption` : State defining the photon energy group</span>
<span class="sd">        option.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">value</span> <span class="o">==</span> <span class="n">GroupOption</span><span class="o">.</span><span class="n">HYBRID</span><span class="o">.</span><span class="n">value</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_grouping_option</span> <span class="o">=</span> <span class="n">GroupOption</span><span class="o">.</span><span class="n">HYBRID</span>
        <span class="k">elif</span> <span class="n">value</span> <span class="o">==</span> <span class="n">GroupOption</span><span class="o">.</span><span class="n">GROUP</span><span class="o">.</span><span class="n">value</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_grouping_option</span> <span class="o">=</span> <span class="n">GroupOption</span><span class="o">.</span><span class="n">GROUP</span>
        <span class="k">elif</span> <span class="n">value</span> <span class="o">==</span> <span class="n">GroupOption</span><span class="o">.</span><span class="n">DISCRETE</span><span class="o">.</span><span class="n">value</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_grouping_option</span> <span class="o">=</span> <span class="n">GroupOption</span><span class="o">.</span><span class="n">DISCRETE</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid grouping option &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">value</span><span class="p">))</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">include_key_progeny</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;bool : State defining if key progeny should be included.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_include_key_progeny</span>

    <span class="nd">@include_key_progeny</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">include_key_progeny</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;bool : State defining if key progeny should be included.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_include_key_progeny</span> <span class="o">=</span> <span class="n">value</span>

<div class="viewcode-block" id="Source.add_isotope_curies"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.Source.add_isotope_curies">[docs]</a>    <span class="k">def</span> <span class="nf">add_isotope_curies</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">new_isotope</span><span class="p">,</span> <span class="n">curies</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Adds an isotope and activity in curies to the isotope list</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        new_isotope : :class:`zapmenot.isotope.Isotope`</span>
<span class="sd">            The isotope to be added to the source.</span>
<span class="sd">        curies : float</span>
<span class="sd">            The activity in curies.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_isotope_list</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">new_isotope</span><span class="p">,</span> <span class="n">curies</span><span class="o">*</span><span class="mf">3.7E10</span><span class="p">))</span></div>

<div class="viewcode-block" id="Source.add_isotope_bq"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.Source.add_isotope_bq">[docs]</a>    <span class="k">def</span> <span class="nf">add_isotope_bq</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">new_isotope</span><span class="p">,</span> <span class="n">becquerels</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Adds an isotope and activity in becquerels to the isotope list</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        new_isotope : :class:`zapmenot.isotope.Isotope`</span>
<span class="sd">            The isotope to be added to the source.</span>
<span class="sd">        becquerels : float</span>
<span class="sd">            The activity in becquerels.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_isotope_list</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">new_isotope</span><span class="p">,</span> <span class="n">becquerels</span><span class="p">))</span></div>

<div class="viewcode-block" id="Source.add_photon"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.Source.add_photon">[docs]</a>    <span class="k">def</span> <span class="nf">add_photon</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">energy</span><span class="p">,</span> <span class="n">intensity</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Adds a photon and intensity to the photon list</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        energy : float</span>
<span class="sd">            The photon energy in MeV.</span>
<span class="sd">        intensity : float</span>
<span class="sd">            The intensity in photons/sec.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_unique_photons</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">energy</span><span class="p">,</span> <span class="n">intensity</span><span class="p">))</span></div>

<div class="viewcode-block" id="Source.list_isotopes"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.Source.list_isotopes">[docs]</a>    <span class="k">def</span> <span class="nf">list_isotopes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Returns a list of isotopes in the source</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`list` of :class:`tuple`</span>
<span class="sd">            List of isotope tuples, each tuple containing a</span>
<span class="sd">            Isotope object and an activity in Bq.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_isotope_list</span></div>

<div class="viewcode-block" id="Source.list_discrete_photons"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.Source.list_discrete_photons">[docs]</a>    <span class="k">def</span> <span class="nf">list_discrete_photons</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Returns a list of individual photons in the source.</span>

<span class="sd">        The list includes only those photons that have been added</span>
<span class="sd">        individually to the source.  It does not include the photons</span>
<span class="sd">        that result from the isotopes added to the source.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`list` of :class:`tuple`</span>
<span class="sd">            List of photon tuples, each tuple containing a</span>
<span class="sd">            photon energy in MeV and an activity in Bq.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_unique_photons</span></div>

    <span class="c1"># def _get_distributed_source_list(self):</span>
    <span class="c1">#     &quot;&quot;&quot;Returns a list of photons in the source</span>

    <span class="c1">#     This list of photons combines the Isotopes and the</span>
    <span class="c1">#     unique_photons specified in the Source definition.</span>
    <span class="c1">#     The photon intensities are scaled to **one source point**.</span>

    <span class="c1">#     Returns</span>
    <span class="c1">#     -------</span>
    <span class="c1">#     :class:`list` of :class:`tuple`</span>
    <span class="c1">#         List of photon tuples, each tuple containing a</span>
    <span class="c1">#         photon energy in MeV and an activity in **Bq//source point**.</span>
    <span class="c1">#     &quot;&quot;&quot;</span>
    <span class="c1">#     list = self.get_photon_source_list()</span>
    <span class="c1">#     scaling_factor = np.prod(self._points_per_dimension)</span>

<div class="viewcode-block" id="Source.get_photon_source_list"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.Source.get_photon_source_list">[docs]</a>    <span class="k">def</span> <span class="nf">get_photon_source_list</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Returns a list of photons in the source</span>

<span class="sd">        This list of photons combines the Isotopes and the</span>
<span class="sd">        unique_photons specified in the Source definition.</span>
<span class="sd">        The photon intensities are scaled to **one source point**.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`list` of :class:`tuple`</span>
<span class="sd">            List of photon tuples, each tuple containing a</span>
<span class="sd">            photon energy in MeV and an activity in **Bq**.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">photon_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
        <span class="n">keys</span> <span class="o">=</span> <span class="n">photon_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>

        <span class="n">temporary_isotope_list</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_isotope_list</span><span class="p">[:]</span>
        <span class="c1"># add key progeny if required</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_include_key_progeny</span> <span class="ow">is</span> <span class="kc">True</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">next_isotope</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_isotope_list</span><span class="p">:</span>
                <span class="n">isotope_detail</span> <span class="o">=</span> <span class="n">isotope</span><span class="o">.</span><span class="n">Isotope</span><span class="p">(</span><span class="n">next_isotope</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="k">if</span> <span class="n">isotope_detail</span><span class="o">.</span><span class="n">key_progeny</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">isotope_detail</span><span class="o">.</span><span class="n">key_progeny</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                        <span class="n">temporary_isotope_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                           <span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">next_isotope</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">value</span><span class="p">))</span>

        <span class="c1"># search isotope list for photons to be added to the photon list</span>
        <span class="c1"># next_isotope will be a tuple of name and Bq</span>
        <span class="k">for</span> <span class="n">next_isotope</span> <span class="ow">in</span> <span class="n">temporary_isotope_list</span><span class="p">:</span>
            <span class="n">isotope_detail</span> <span class="o">=</span> <span class="n">isotope</span><span class="o">.</span><span class="n">Isotope</span><span class="p">(</span><span class="n">next_isotope</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">isotope_detail</span><span class="o">.</span><span class="n">photons</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">photon</span> <span class="ow">in</span> <span class="n">isotope_detail</span><span class="o">.</span><span class="n">photons</span><span class="p">:</span>
                    <span class="c1"># test to see if photon energy is already on the list</span>
                    <span class="c1"># and then add photon emission rate (intensity*Bq).</span>
                    <span class="k">if</span> <span class="n">photon</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">in</span> <span class="n">keys</span><span class="p">:</span>
                        <span class="n">photon_dict</span><span class="p">[</span><span class="n">photon</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">=</span> <span class="n">photon_dict</span><span class="p">[</span><span class="n">photon</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">+</span> \
                            <span class="n">photon</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">next_isotope</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">photon_dict</span><span class="p">[</span><span class="n">photon</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">=</span> <span class="n">photon</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">next_isotope</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">photon</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_unique_photons</span><span class="p">:</span>
            <span class="c1"># test to see if photon energy is already on the list</span>
            <span class="c1"># and then add photon emission rate.</span>
            <span class="k">if</span> <span class="n">photon</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">in</span> <span class="n">keys</span><span class="p">:</span>
                <span class="n">photon_dict</span><span class="p">[</span><span class="n">photon</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">=</span> <span class="n">photon_dict</span><span class="p">[</span><span class="n">photon</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">+</span> <span class="n">photon</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">photon_dict</span><span class="p">[</span><span class="n">photon</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">=</span> <span class="n">photon</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">photon_list</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="c1"># scaling_factor = np.prod(self._points_per_dimension)</span>
        <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">photon_dict</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">photon_list</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">))</span>
        <span class="n">photon_list</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">photon_list</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_grouping_option</span> <span class="o">==</span> <span class="n">GroupOption</span><span class="o">.</span><span class="n">GROUP</span> <span class="ow">or</span> \
                <span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">_grouping_option</span> <span class="o">==</span> <span class="n">GroupOption</span><span class="o">.</span><span class="n">HYBRID</span><span class="p">)</span> <span class="ow">and</span>
                    <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">photon_list</span><span class="p">)</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">_max_photon_energies</span><span class="p">)):</span>
            <span class="c1"># group the photons</span>
            <span class="n">minEnergy</span> <span class="o">=</span> <span class="n">photon_list</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">maxEnergy</span> <span class="o">=</span> <span class="n">photon_list</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
            <span class="p">(</span><span class="n">groupEnergies</span><span class="p">,</span> <span class="n">stepSize</span><span class="p">)</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span>
                <span class="n">minEnergy</span><span class="p">,</span> <span class="n">maxEnergy</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_max_photon_energies</span><span class="p">,</span> <span class="n">retstep</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
            <span class="n">binBoundaries</span> <span class="o">=</span> <span class="n">groupEnergies</span> <span class="o">+</span> <span class="p">(</span><span class="n">stepSize</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span>
            <span class="n">binBoundaries</span> <span class="o">=</span> \
                <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">([</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">binBoundaries</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="n">stepSize</span><span class="p">]),</span>
                                <span class="n">binBoundaries</span><span class="p">])</span>
            <span class="c1"># Returns the appropriate bin for each photon</span>
            <span class="n">binplace</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">digitize</span><span class="p">(</span><span class="n">photon_list</span><span class="p">,</span> <span class="n">binBoundaries</span><span class="p">)[:,</span> <span class="mi">0</span><span class="p">]</span>
            <span class="c1"># convert the photon list to an array for further processing</span>
            <span class="n">photonArray</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">photon_list</span><span class="p">)</span>
            <span class="n">returnValue</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">_max_photon_energies</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_max_photon_energies</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
                <span class="c1"># determine which photons are in each bin</span>
                <span class="n">subset</span> <span class="o">=</span> <span class="n">photonArray</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">binplace</span> <span class="o">==</span> <span class="n">i</span><span class="p">)]</span>
                <span class="n">csum</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">subset</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">])</span>  <span class="c1"># total emission rate</span>
                <span class="k">if</span> <span class="p">(</span><span class="n">csum</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">):</span>
                    <span class="n">returnValue</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">subset</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="n">subset</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">])</span><span class="o">/</span><span class="n">csum</span>
                    <span class="n">returnValue</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">csum</span>
            <span class="c1"># keep only groups with non-zero intensity</span>
            <span class="n">returnValue</span> <span class="o">=</span> <span class="n">returnValue</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">all</span><span class="p">(</span><span class="n">returnValue</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)]</span>
            <span class="n">photon_list</span> <span class="o">=</span> <span class="n">returnValue</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">photon_list</span></div>

    <span class="nd">@abc</span><span class="o">.</span><span class="n">abstractmethod</span>
    <span class="k">def</span> <span class="nf">_get_source_points</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">pass</span>

    <span class="nd">@abc</span><span class="o">.</span><span class="n">abstractmethod</span>
    <span class="k">def</span> <span class="nf">_get_source_point_weights</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">pass</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">points_per_dimension</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;list of integers : Number of source points per dimension.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span>

    <span class="nd">@points_per_dimension</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">points_per_dimension</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;list of integers : Number of source points per dimension.&quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="nb">iter</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">TypeError</span><span class="p">:</span>
            <span class="c1"># not iterable; make it so</span>
            <span class="n">value</span> <span class="o">=</span> <span class="p">[</span><span class="n">value</span><span class="p">]</span>
        <span class="c1"># verify the list includes only integers</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">all</span><span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">value</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;Number of Source Points per Dimension is/are non-integer&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">all</span><span class="p">(</span><span class="n">item</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">value</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;Source Points per Dimension must be positive integers&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span> <span class="o">=</span> <span class="n">value</span></div>


<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="LineSource"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.LineSource">[docs]</a><span class="k">class</span> <span class="nc">LineSource</span><span class="p">(</span><span class="n">Source</span><span class="p">,</span> <span class="n">shield</span><span class="o">.</span><span class="n">Shield</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;Models a line radiation source</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    start : :class:`list`</span>
<span class="sd">        Cartiesian X, Y, and Z coordinates of the starting point of the</span>
<span class="sd">        line source.</span>
<span class="sd">    end : :class:`list`</span>
<span class="sd">        Cartiesian X, Y, and Z coordinates of the ending point of the</span>
<span class="sd">        line source.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<span class="w">    </span><span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    material : :class: `material.Material`</span>
<span class="sd">        Material properties of the shield</span>
<span class="sd">    origin : :class:`numpy.ndarray`</span>
<span class="sd">        Vector location of one end of the line source.</span>
<span class="sd">    end : :class:`numpy.ndarray`</span>
<span class="sd">        Vector location of one end of the line source.</span>
<span class="sd">    &#39;&#39;&#39;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="s2">&quot;Initialize&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">origin</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">start</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">end</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">end</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_length</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">end</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">origin</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_dir</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">end</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">origin</span><span class="p">)</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">_length</span>
        <span class="c1"># let the point source have a dummy material of air at a zero density</span>
        <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;material_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;air&#39;</span>
        <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;density&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="c1"># initialize points_per_dimension after super() to force a</span>
        <span class="c1"># single dimension</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span> <span class="o">=</span> <span class="p">[</span><span class="mi">10</span><span class="p">]</span>

<div class="viewcode-block" id="LineSource.is_infinite"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.LineSource.is_infinite">[docs]</a>    <span class="k">def</span> <span class="nf">is_infinite</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Returns true if any dimension is infinite, false otherwise</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="kc">False</span></div>

    <span class="k">def</span> <span class="nf">_get_source_point_weights</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">[</span><span class="mf">1.0</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">)]</span> <span class="o">*</span> \
            <span class="n">np</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_source_points</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Generates a list of point sources within the Source geometry.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`list` of :class:`numpy.adarray`</span>
<span class="sd">            A list of vector locations within the Source body</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1">#</span>
        <span class="c1"># Note: the Line source is unique in that it only has one dimension</span>
        <span class="c1"># (i.e. not three).  Hence it is possible that the user will set the</span>
        <span class="c1"># &quot;points_er_dimension&quot; to be a non-iterable numerical value.</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="nb">iter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">TypeError</span><span class="p">:</span>
            <span class="c1"># not iterable; make it so</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">]</span>

        <span class="n">spacings</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                               <span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="n">mesh_width</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_length</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">spacings</span> <span class="o">=</span> <span class="n">spacings</span><span class="o">*</span><span class="n">mesh_width</span>
        <span class="n">spacings</span> <span class="o">=</span> <span class="n">spacings</span><span class="o">-</span><span class="p">(</span><span class="n">mesh_width</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span>
        <span class="n">source_points</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">dist</span> <span class="ow">in</span> <span class="n">spacings</span><span class="p">:</span>
            <span class="n">location</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">origin</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">_dir</span><span class="o">*</span><span class="n">dist</span>
            <span class="n">source_points</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">location</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">source_points</span>

    <span class="k">def</span> <span class="nf">_get_crossing_length</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ray</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the linear intersection length of a ray and the shield</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        ray : :class:`zapmenot.ray.FiniteLengthRay`</span>
<span class="sd">            The finite length ray that is checked for intersections with</span>
<span class="sd">            the shield.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        int</span>
<span class="sd">            Always returns 0</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="mi">0</span>

<div class="viewcode-block" id="LineSource.get_crossing_mfp"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.LineSource.get_crossing_mfp">[docs]</a>    <span class="k">def</span> <span class="nf">get_crossing_mfp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ray</span><span class="p">,</span> <span class="n">photon_energy</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the mfp equivalent if a ray intersects the shield</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        ray : :class:`zapmenot.ray.FiniteLengthRay`</span>
<span class="sd">            The finite length ray that is checked for intersections with</span>
<span class="sd">            the shield.</span>
<span class="sd">        photon_energy : float</span>
<span class="sd">            The photon energy in MeV</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        int</span>
<span class="sd">            Always returns 0</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="mi">0</span></div>

<div class="viewcode-block" id="LineSource.draw"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.LineSource.draw">[docs]</a>    <span class="k">def</span> <span class="nf">draw</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Creates a display object</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`pyvista.PolyData`</span>
<span class="sd">            A line object representing the line source.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">pyvista_found</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">pyvista</span><span class="o">.</span><span class="n">Line</span><span class="p">(</span><span class="n">pointa</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">origin</span><span class="p">,</span> <span class="n">pointb</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">end</span><span class="p">)</span></div></div>

<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="PointSource"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.PointSource">[docs]</a><span class="k">class</span> <span class="nc">PointSource</span><span class="p">(</span><span class="n">Source</span><span class="p">,</span> <span class="n">shield</span><span class="o">.</span><span class="n">Shield</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;Models a point radiation source</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    x : float</span>
<span class="sd">        Cartesian X coordinate of the point source.</span>
<span class="sd">    y : float</span>
<span class="sd">        Cartesian Y coordinate of the point source.</span>
<span class="sd">    z : float</span>
<span class="sd">        Cartesian Z coordinate of the point source.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<span class="w">    </span><span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    material : :class: `zapmenot.material.Material`</span>
<span class="sd">        Material properties of the shield</span>
<span class="sd">    inner_radius : float</span>
<span class="sd">        Radius of the annulus inner surface.</span>
<span class="sd">    outer_radius : float</span>
<span class="sd">        Radius of the annulus outer surface.</span>
<span class="sd">    origin : :class:`numpy.ndarray`</span>
<span class="sd">        Vector location of a point on the annulus centerline.</span>
<span class="sd">    dir : :class:`numpy.ndarray`</span>
<span class="sd">        Vector normal of the annulus centerline.</span>
<span class="sd">    &#39;&#39;&#39;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&#39;&#39;&#39;Initialize with an x,y,z location in space&#39;&#39;&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_x</span> <span class="o">=</span> <span class="n">x</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_y</span> <span class="o">=</span> <span class="n">y</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_z</span> <span class="o">=</span> <span class="n">z</span>
        <span class="c1"># let the point source have a dummy material of air at a zero density</span>
        <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;material_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;air&#39;</span>
        <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;density&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span>

<div class="viewcode-block" id="PointSource.is_infinite"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.PointSource.is_infinite">[docs]</a>    <span class="k">def</span> <span class="nf">is_infinite</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Returns true if any dimension is infinite, false otherwise</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="kc">False</span></div>

    <span class="k">def</span> <span class="nf">_get_source_point_weights</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">[</span><span class="mf">1.0</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">)]</span> <span class="o">*</span> \
            <span class="n">np</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_source_points</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Generates a list of point sources within the Source geometry.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`list` of :class:`numpy.adarray`</span>
<span class="sd">            A list of vector locations within the Source body.  In this class</span>
<span class="sd">            the list is only a single entry.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">[(</span><span class="bp">self</span><span class="o">.</span><span class="n">_x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_y</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_z</span><span class="p">)]</span>

    <span class="k">def</span> <span class="nf">_get_crossing_length</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ray</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the linear intersection length of a ray and the shield</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        ray : :class:`zapmenot.ray.FiniteLengthRay`</span>
<span class="sd">            The finite length ray that is checked for intersections with</span>
<span class="sd">            the shield.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        int</span>
<span class="sd">            Always returns 0</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="mi">0</span>

<div class="viewcode-block" id="PointSource.get_crossing_mfp"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.PointSource.get_crossing_mfp">[docs]</a>    <span class="k">def</span> <span class="nf">get_crossing_mfp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ray</span><span class="p">,</span> <span class="n">photon_energy</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the mfp equivalent if a ray intersects the shield</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        ray : :class:`zapmenot.ray.FiniteLengthRay`</span>
<span class="sd">            The finite length ray that is checked for intersections with</span>
<span class="sd">            the shield.</span>
<span class="sd">            Always returns 0 for the Point source.</span>
<span class="sd">        photon_energy : float</span>
<span class="sd">            The photon energy in MeV</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        int</span>
<span class="sd">            Always returns 0</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="mi">0</span></div>

<div class="viewcode-block" id="PointSource.draw"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.PointSource.draw">[docs]</a>    <span class="k">def</span> <span class="nf">draw</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Creates a display object</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`pyvista.PolyData`</span>
<span class="sd">            A degenerate line object representing the point source.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">pyvista_found</span><span class="p">:</span>
            <span class="c1"># this returns a degenerate line, equivalent to a point</span>
            <span class="k">return</span> <span class="n">pyvista</span><span class="o">.</span><span class="n">Line</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">_x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_y</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_z</span><span class="p">),</span>
                                <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_y</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_z</span><span class="p">))</span></div></div>


<span class="c1"># -----------------------------------------------------------</span>


<span class="c1"># class SphereSource(Source, shield.Sphere):</span>
<span class="c1">#     &#39;&#39;&#39;Axis-Aligned rectangular box source&#39;&#39;&#39;</span>
<span class="c1">#     # initialize with box_center, box_dimensions, material(optional),</span>
<span class="c1">#     # density(optional)</span>

<span class="c1">#     def __init__(self, **kwargs):</span>
<span class="c1">#         super().__init__(**kwargs)</span>

<span class="c1">#    def _get_source_point_weights(self):</span>
<span class="c1">#         pass</span>

<span class="c1">#     def _get_source_points(self):</span>

<span class="c1">#         # calculate the radius of each &quot;equal area&quot; annular region</span>
<span class="c1">#         totalVolume = 4/3*math.pi*self.radius**3</span>
<span class="c1">#         old_radius = 0</span>
<span class="c1">#         annular_locations = []</span>
<span class="c1">#         for i in range(self._points_per_dimension[0]):</span>
<span class="c1">#             new_radius = math.sqrt((running_area+annular_area)/math.pi)</span>
<span class="c1">#             annular_locations.append((new_radius+old_radius)/2)</span>
<span class="c1">#             old_radius = new_radius</span>

<span class="c1">#         angle_increment = 2*math.pi/self._points_per_dimension[1]</span>
<span class="c1">#         start_angle = angle_increment/2</span>
<span class="c1">#         angle_locations = []</span>
<span class="c1">#         for i in range(self._points_per_dimension[1]):</span>
<span class="c1">#             angle_locations.append(start_angle + (i*angle_increment))</span>

<span class="c1">#         length_increment = self.length/self._points_per_dimension[2]</span>
<span class="c1">#         start_length = length_increment/2</span>
<span class="c1">#         length_locations = []</span>
<span class="c1">#         for i in range(self._points_per_dimension[2]):</span>
<span class="c1">#             length_locations.append(start_length + (i*length_increment))</span>

<span class="c1">#         # iterate through each dimension, building a list of source points</span>
<span class="c1">#         source_points = []</span>
<span class="c1">#         for radial_location in annular_locations:</span>
<span class="c1">#             r = radial_location</span>
<span class="c1">#             for angle_location in angle_locations:</span>
<span class="c1">#                 theta = angle_location</span>
<span class="c1">#                 for length_location in length_locations:</span>
<span class="c1">#                     z = length_location</span>
<span class="c1">#                     # convert cylindrical to rectangular coordinates</span>
<span class="c1">#                     x = r * math.cos(theta)</span>
<span class="c1">#                     y = r * math.sin(theta)</span>
<span class="c1">#                     source_points.append([x, y, z])</span>
<span class="c1">#         return source_points</span>

<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="BoxSource"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.BoxSource">[docs]</a><span class="k">class</span> <span class="nc">BoxSource</span><span class="p">(</span><span class="n">Source</span><span class="p">,</span> <span class="n">shield</span><span class="o">.</span><span class="n">Box</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;Models a Axis-Aligned rectangular box source</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    material_name : :class:`zapmenot.material.Material`</span>
<span class="sd">        Shield material type</span>
<span class="sd">    box_center : :class:`list`</span>
<span class="sd">        X, Y, and Z coordinates of the box center.</span>
<span class="sd">    box_dimensions : :class:`list`</span>
<span class="sd">        X, Y, and Z dimensions of the box.</span>
<span class="sd">    density : float, optional</span>
<span class="sd">        Material density in g/cm3.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<span class="w">    </span><span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    material : :class: `material.Material`</span>
<span class="sd">        Material properties of the shield</span>
<span class="sd">    &#39;&#39;&#39;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_source_point_weights</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">[</span><span class="mf">1.0</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">)]</span> <span class="o">*</span> \
            <span class="n">np</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_source_points</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Generates a list of point sources within the Source geometry.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`list` of :class:`numpy.adarray`</span>
<span class="sd">            A list of vector locations within the Source body.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">source_points</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="c1"># verify there are three values in the list</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">3</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;Source Points per Dimension needs three entries&quot;</span><span class="p">)</span>
        <span class="n">mesh_width</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">box_dimensions</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span>
        <span class="n">start_point</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">box_center</span><span class="o">-</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">box_dimensions</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="o">+</span><span class="p">(</span><span class="n">mesh_width</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
            <span class="n">x</span> <span class="o">=</span> <span class="n">start_point</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">mesh_width</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="n">i</span>
            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span>
                <span class="n">y</span> <span class="o">=</span> <span class="n">start_point</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="n">mesh_width</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">j</span>
                <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">[</span><span class="mi">2</span><span class="p">]):</span>
                    <span class="n">z</span> <span class="o">=</span> <span class="n">start_point</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">+</span><span class="n">mesh_width</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">*</span><span class="n">k</span>
                    <span class="n">source_points</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">])</span>
        <span class="k">return</span> <span class="n">source_points</span></div>

<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="ZAlignedCylinderSource"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.ZAlignedCylinderSource">[docs]</a><span class="k">class</span> <span class="nc">ZAlignedCylinderSource</span><span class="p">(</span><span class="n">Source</span><span class="p">,</span> <span class="n">shield</span><span class="o">.</span><span class="n">ZAlignedCylinder</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;Models a cylindrical source axis-aligned with the Z axis.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    material_name : :obj:`material.Material`</span>
<span class="sd">        Shield material type</span>
<span class="sd">    cylinder_center : :obj:`list`</span>
<span class="sd">        X, Y, and Z coordinates of the center of the cylinder.</span>
<span class="sd">    cylinder_length : float</span>
<span class="sd">        The length of the cylinder.</span>
<span class="sd">    cylinder_radius : float</span>
<span class="sd">        Radius of the cylinder.</span>
<span class="sd">    density : float, optional</span>
<span class="sd">        Material density in g/cm3.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># initialize with cylinderCenter, cylinderLength, cylinderRadius,</span>
    <span class="c1"># material(optional), density(optional)</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_source_point_weights</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">[</span><span class="mf">1.0</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">)]</span> <span class="o">*</span> \
            <span class="n">np</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_source_points</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Generates a list of point sources within the Source geometry.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`list` of :class:`numpy.adarray`</span>
<span class="sd">            A list of vector locations within the Source body.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># verify there are three values in the list</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">3</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;Source Points per Dimension needs three entries&quot;</span><span class="p">)</span>
        <span class="n">source_points</span> <span class="o">=</span> <span class="n">_generic_cylinder_source_points</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">,</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">length</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">radius</span><span class="p">)</span>
        <span class="c1"># no rotation is needed</span>
        <span class="c1"># shift the point set to the specified cylinder center</span>
        <span class="n">source_points</span> <span class="o">+=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">origin</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">end</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span>
        <span class="k">return</span> <span class="n">source_points</span></div>

<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="YAlignedCylinderSource"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.YAlignedCylinderSource">[docs]</a><span class="k">class</span> <span class="nc">YAlignedCylinderSource</span><span class="p">(</span><span class="n">Source</span><span class="p">,</span> <span class="n">shield</span><span class="o">.</span><span class="n">YAlignedCylinder</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;Models a cylindrical source axis-aligned with the Y axis.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    material_name : :obj:`material.Material`</span>
<span class="sd">        Shield material type</span>
<span class="sd">    cylinder_center : :obj:`list`</span>
<span class="sd">        X, Y, and Z coordinates of the center of the cylinder.</span>
<span class="sd">    cylinder_length : float</span>
<span class="sd">        The length of the cylinder.</span>
<span class="sd">    cylinder_radius : float</span>
<span class="sd">        Radius of the cylinder.</span>
<span class="sd">    density : float, optional</span>
<span class="sd">        Material density in g/cm3.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># initialize with cylinderCenter, cylinderLength, cylinderRadius,</span>
    <span class="c1"># material(optional), density(optional)</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_source_point_weights</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">[</span><span class="mf">1.0</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">)]</span> <span class="o">*</span> \
            <span class="n">np</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_source_points</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Generates a list of point sources within the Source geometry.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`list` of :class:`numpy.adarray`</span>
<span class="sd">            A list of vector locations within the Source body.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># verify there are three values in the list</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">3</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;Source Points per Dimension needs three entries&quot;</span><span class="p">)</span>
        <span class="n">some_points</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">_generic_cylinder_source_points</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">,</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">length</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">radius</span><span class="p">))</span>
        <span class="c1"># rotate the point set from the Z-axis to the Y-axis</span>
        <span class="c1"># (y replaced by z; z replaced by -y)</span>
        <span class="n">source_points</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">empty_like</span><span class="p">(</span><span class="n">some_points</span><span class="p">)</span>
        <span class="n">source_points</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">some_points</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span>
        <span class="n">source_points</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">some_points</span><span class="p">[:,</span> <span class="mi">2</span><span class="p">]</span>
        <span class="n">source_points</span><span class="p">[:,</span> <span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="n">some_points</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span>
        <span class="c1"># shift the point set to the specified cylinder center</span>
        <span class="n">source_points</span> <span class="o">+=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">origin</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">end</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span>
        <span class="k">return</span> <span class="n">source_points</span></div>

<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="XAlignedCylinderSource"><a class="viewcode-back" href="../../module-docs.html#zapmenot.source.XAlignedCylinderSource">[docs]</a><span class="k">class</span> <span class="nc">XAlignedCylinderSource</span><span class="p">(</span><span class="n">Source</span><span class="p">,</span> <span class="n">shield</span><span class="o">.</span><span class="n">XAlignedCylinder</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;Models a cylindrical source axis-aligned with the X axis.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    material_name : :obj:`material.Material`</span>
<span class="sd">        Shield material type</span>
<span class="sd">    cylinder_center : :obj:`list`</span>
<span class="sd">        X, Y, and Z coordinates of the center of the cylinder.</span>
<span class="sd">    cylinder_length : float</span>
<span class="sd">        The length of the cylinder.</span>
<span class="sd">    cylinder_radius : float</span>
<span class="sd">        Radius of the cylinder.</span>
<span class="sd">    density : float, optional</span>
<span class="sd">        Material density in g/cm3.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># initialize with cylinderCenter, cylinderLength, cylinderRadius,</span>
    <span class="c1"># material(optional), density(optional)</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_source_point_weights</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">[</span><span class="mf">1.0</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">)]</span> <span class="o">*</span> \
            <span class="n">np</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_source_points</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Generates a list of point sources within the Source geometry.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`list` of :class:`numpy.adarray`</span>
<span class="sd">            A list of vector locations within the Source body.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># verify there are three values in the list</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">3</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;Source Points per Dimension needs three entries&quot;</span><span class="p">)</span>
        <span class="n">some_points</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">_generic_cylinder_source_points</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_points_per_dimension</span><span class="p">,</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">length</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">radius</span><span class="p">))</span>
        <span class="c1"># rotate the point set from the Z-axis to the Y-axis</span>
        <span class="c1"># (x replaced by z; z replaced by -x)</span>
        <span class="n">source_points</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">empty_like</span><span class="p">(</span><span class="n">some_points</span><span class="p">)</span>
        <span class="n">source_points</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">some_points</span><span class="p">[:,</span> <span class="mi">2</span><span class="p">]</span>
        <span class="n">source_points</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">some_points</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span>
        <span class="n">source_points</span><span class="p">[:,</span> <span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="n">some_points</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span>
        <span class="c1"># shift the point set to the specified cylinder center</span>
        <span class="n">source_points</span> <span class="o">+=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">origin</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">end</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span>
        <span class="k">return</span> <span class="n">source_points</span></div>


<span class="k">def</span> <span class="nf">_generic_cylinder_source_points</span><span class="p">(</span><span class="n">points_per_dimension</span><span class="p">,</span> <span class="n">length</span><span class="p">,</span> <span class="n">radius</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;Generates a list of point sources within a Z-aligned</span>
<span class="sd">    cylinder centered on the origin.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    :class:`list` of :class:`numpy.adarray`</span>
<span class="sd">        A list of vector locations within the Source body.</span>

<span class="sd">    Arguments</span>
<span class="sd">    ----------</span>
<span class="sd">    points_per_dimension : :obj:`list`</span>
<span class="sd">        list of number of quadrature points per dimension: r, theta, z</span>
<span class="sd">    length : float</span>
<span class="sd">        The length of the cylinder.</span>
<span class="sd">    radius : float</span>
<span class="sd">        The radius of the cylinder.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># calculate the radius of each &quot;equal area&quot; annular region</span>
    <span class="n">total_area</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">pi</span><span class="o">*</span><span class="n">radius</span><span class="o">**</span><span class="mi">2</span>
    <span class="n">annular_area</span> <span class="o">=</span> <span class="n">total_area</span><span class="o">/</span><span class="n">points_per_dimension</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    <span class="n">old_radius</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">running_area</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">annular_locations</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">points_per_dimension</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
        <span class="n">new_radius</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">((</span><span class="n">running_area</span><span class="o">+</span><span class="n">annular_area</span><span class="p">)</span><span class="o">/</span><span class="n">math</span><span class="o">.</span><span class="n">pi</span><span class="p">)</span>
        <span class="n">annular_locations</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">new_radius</span><span class="o">+</span><span class="n">old_radius</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span>
        <span class="n">old_radius</span> <span class="o">=</span> <span class="n">new_radius</span>
        <span class="n">running_area</span> <span class="o">=</span> <span class="n">running_area</span><span class="o">+</span><span class="n">annular_area</span>

    <span class="n">angle_increment</span> <span class="o">=</span> <span class="mi">2</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">pi</span><span class="o">/</span><span class="n">points_per_dimension</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
    <span class="n">start_angle</span> <span class="o">=</span> <span class="n">angle_increment</span><span class="o">/</span><span class="mi">2</span>
    <span class="n">angle_locations</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">points_per_dimension</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span>
        <span class="n">angle_locations</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">start_angle</span> <span class="o">+</span> <span class="p">(</span><span class="n">i</span><span class="o">*</span><span class="n">angle_increment</span><span class="p">))</span>

    <span class="n">length_increment</span> <span class="o">=</span> <span class="n">length</span><span class="o">/</span><span class="n">points_per_dimension</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
    <span class="n">start_location</span> <span class="o">=</span> <span class="o">-</span><span class="p">(</span><span class="n">length</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="n">length_increment</span><span class="o">/</span><span class="mi">2</span>
    <span class="n">length_locations</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">points_per_dimension</span><span class="p">[</span><span class="mi">2</span><span class="p">]):</span>
        <span class="n">length_locations</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">start_location</span> <span class="o">+</span> <span class="p">(</span><span class="n">i</span><span class="o">*</span><span class="n">length_increment</span><span class="p">))</span>

    <span class="c1"># iterate through each dimension, building a list of source points</span>
    <span class="n">source_points</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">radial_location</span> <span class="ow">in</span> <span class="n">annular_locations</span><span class="p">:</span>
        <span class="n">r</span> <span class="o">=</span> <span class="n">radial_location</span>
        <span class="k">for</span> <span class="n">angle_location</span> <span class="ow">in</span> <span class="n">angle_locations</span><span class="p">:</span>
            <span class="n">theta</span> <span class="o">=</span> <span class="n">angle_location</span>
            <span class="k">for</span> <span class="n">length_location</span> <span class="ow">in</span> <span class="n">length_locations</span><span class="p">:</span>
                <span class="n">z</span> <span class="o">=</span> <span class="n">length_location</span>
                <span class="c1"># convert cylindrical to rectangular coordinates</span>
                <span class="n">x</span> <span class="o">=</span> <span class="n">r</span> <span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">)</span>
                <span class="n">y</span> <span class="o">=</span> <span class="n">r</span> <span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">)</span>
                <span class="n">source_points</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">])</span>
    <span class="k">return</span> <span class="n">source_points</span>
</pre></div>

           </div>
          </div>
          <footer>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2019 - 2023, Alan Ford..
      <span class="lastupdated">Last updated on Feb 12, 2023.
      </span></p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>